package com.matrix.gallery.ui.wallpaper.viewmodel

import android.os.Environment
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.matrix.basecore.constant.Constant
import com.matrix.gallery.respository.WallpaperResp
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream

class PreviewVM : ViewModel() {
    //suspend 暂不支持下载文件（todo）
    fun getDownload(url: String): LiveData<Call<ResponseBody>> {
        return flow {
            val call = WallpaperResp.downloadImage(url)
            emit(call)
        }.catch { ex ->
            LogUtils.i("error:" + ex.toString())
        }.asLiveData()
    }

    fun getDownloads(url: String): Call<ResponseBody> {
        return WallpaperResp.downloadImages(url)
    }
}